package com.ctg.itrdc.imageconsole.data.dao.impl;

import java.util.List;

import org.springframework.stereotype.Component;

import com.ctg.itrdc.imageconsole.data.dao.IDockerMicroImageContentDao;
import com.ctg.itrdc.imageconsole.data.entity.DockerMicroImageContent;
import com.ctg.itrdc.paspsdk.data.dao.impl.BaseDaoImpl;

@Component("dockerMicroImageContentDao")
public class DockerMicroImageContentDaoImpl extends BaseDaoImpl implements IDockerMicroImageContentDao{

	@Override
	public String selectOneUploadFile(Long dockerMicroImageId) 
	{
		DockerMicroImageContent content = new DockerMicroImageContent();
		content.setDockerMicroImageId(dockerMicroImageId);
		List<DockerMicroImageContent> contentList = super.selectByExample(content);
		if(contentList.isEmpty())
			throw new NullPointerException("Error : selecting docker_micro_image_content by docker_micro_image_id returns 0 records");
		String uploadFile = null;
		for(DockerMicroImageContent entity : contentList)
		{
			uploadFile = entity.getUploadFile();
			if(null == uploadFile)
				throw new NullPointerException("Error : upload_file is null");
			if(uploadFile.contains(".war") || uploadFile.contains(".jar"))
				return uploadFile.substring(0, uploadFile.length() - 4);
		}				
		return null;
	}

}
